home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 March
/
Chip_2002-03_cd1.bin
/
zkuste
/
delphi
/
kolekce
/
d3456
/
gmprintsuite_eval.exe
/
{app}
/
GmTreeViewPrint.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2002-01-02
|
6KB
|
165 lines
{******************************************************************************}
{ }
{ TGmTreeViewPrint 2.3 }
{ }
{ Copyright (c) 2001 Graham Murt - www.MurtSoft.com }
{ }
{ Feel free to e-mail me with any comments, suggestions, bugs or help at: }
{ }
{ graham@murtsoft.com }
{ }
{******************************************************************************}
unit GmTreeViewPrint;
interface
uses
Windows, Messages, SysUtils, Classes, ComCtrls, Forms, GmPreview;
type
TGmTreeViewPrint = class(TComponent)
private
FExpandNodes: Boolean;
FIndent: TGmValue;
FItemHeight: TGmValue;
FPreview: TGmPreview;
{ Private declarations }
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure TreeViewToPage(X, Y: integer; AUnits: TGmMeasurement; ATreeView: TTreeView);
property Indent: TGmValue read FIndent write FIndent;
property ItemHeight: TGmValue read FItemHeight write FItemHeight;
{ Public declarations }
published
property ExpandNodes: Boolean read FExpandNodes write FExpandNodes default True;
property Preview: TGmPreview read FPreview write FPreview;
{ Published declarations }
end;
implementation
uses Graphics, GmConst;
constructor TGmTreeViewPrint.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FExpandNodes := True;
FIndent := TGmValue.Create;
FIndent.AsUnits := 600;
FItemHeight := TGmValue.Create;
FItemHeight.AsUnits := 600;
end;
destructor TGmTreeViewPrint.Destroy;
begin
FIndent.Free;
FItemHeight.Free;
inherited Destroy;
end;
procedure TGmTreeViewPrint.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FPreview) then
FPreview := nil;
end;
procedure TGmTreeViewPrint.TreeViewToPage(X, Y: integer; AUnits: TGmMeasurement; ATreeView: TTreeView);
var
TreeView: TTreeView;
AForm: TForm;
ICount: integer;
StartX,
CurrentY: integer;
StartY,
CurrentX: integer;
Image: TBitmap;
AIndent: integer;
ImageHeight: integer;
ImageWidth: integer;
LevelChanged: Boolean;
LastLevel: integer;
//CurrentNode: integer;
IsVisible: Boolean;
begin
LastLevel := 0;
if Assigned(FPreview) then
begin
TreeView := TTreeView.Create(nil);
AForm := TForm.Create(nil);
TreeView.Parent := AForm;
Image := TBitmap.Create;
try
TreeView.Items.Assign(ATreeView.Items);
TreeView.Images := ATreeView.Images;
if FExpandNodes then TreeView.FullExpand;
StartX := Round(ConvertValue(X, AUnits, GmUnits));
StartY := Round(ConvertValue(Y, AUnits, GmUnits));
CurrentY := StartY;
for ICount := 0 to TreeView.Items.Count-1 do
begin
if FExpandNodes then IsVisible := True else
IsVisible := ATreeView.Items[ICount].IsVisible;
if (IsVisible) then
with FPreview.Canvas do
begin
Pen.Color := clSilver;
//Pen.Style := psDot;
AIndent := Indent.AsUnits;
LevelChanged := LastLevel <> TreeView.Items[ICount].Level+1;
LastLevel := TreeView.Items[ICount].Level+1;
CurrentX := StartX + (AIndent * (LastLevel));
//CurrentY := StartY + (FItemHeight.AsUnits * (CurrentNode));
Image.Canvas.FillRect(Rect(0,0,Image.Width, Image.Height));
TreeView.Images.GetBitmap(TreeView.Items[ICount].ImageIndex, Image);
ImageHeight := Round((Image.Height * 2540) / Screen.PixelsPerInch);
ImageWidth := Round((Image.Width * 2540) / Screen.PixelsPerInch);
Line(StartX, CurrentY, StartX, CurrentY+FItemHeight.AsUnits, GmUnits);
MoveTo(CurrentX - (ImageWidth div 2) - 50,
CurrentY ,//+ (ImageHeight div 2),
GmUnits);
LineTo(CurrentX -(Indent.AsUnits),
CurrentY ,//+ (ImageHeight div 2),
GmUnits);
if LevelChanged then
LineTo(CurrentX -(Indent.AsUnits),
CurrentY - (FItemHeight.AsUnits-(ImageHeight div 2))+50,
GmUnits)
else
LineTo(CurrentX -(Indent.AsUnits),
CurrentY - (FItemHeight.AsUnits),
GmUnits);
Draw(CurrentX - (ImageWidth div 2), CurrentY - (ImageHeight div 2), Image, 1, GmUnits);
TextOut(CurrentX + ImageWidth, CurrentY-(ImageHeight div 2), TreeView.Items[ICount].Text, GmUnits);
if CurrentY > (FPreview.PageHeight.AsUnits - (FPreview.Margins.Bottom.AsUnits + +FPreview.Header.Height.AsUnits + 1000)) then
begin
CurrentY := StartY;
FPreview.NewPage;
end
else
Inc(CurrentY, FItemHeight.AsUnits);
end;
//FPreview.Canvas.Line(3000, CurrentY, 6000, CurrentY, GmUnits);
end;
finally
TreeView.Free;
AForm.Free;
Image.Free;
FPreview.UpdatePreview;
end;
end;
end;
end.